package BeenChina.PM.Action;
import java.util.ArrayList;
import java.util.List;

import BeenChina.PM.Model.ModelRole;  
import BeenChina.PM.Service.ServiceFactory;
import BeenChina.PM.Util.JqGridBaseAction;
import BeenChina.PM.Util.Permission;

public class RoleInfoQueryAction extends JqGridBaseAction<ModelRole> {	

	private static final long serialVersionUID = 1L;
	 
	private List<ModelRole> roles = new ArrayList<ModelRole>();

	@Override
	 public String execute() { 
		 return "load";
	 }
	
	@Override
	public int getResultSize() {
		 
		return roles.size();
	}

	@Override
	protected List<ModelRole> listResults(int from, int length)
			throws Exception {
		roles = ServiceFactory.getInstance().getSystemInfoService().selectRoles();
		
		roles = getViewPermissions( roles );
		return roles;
	} 
	
	private List<ModelRole> getViewPermissions(List<ModelRole> rolesList) {
		
		for (ModelRole model : rolesList) {
			
			String oldString = model.getPermissions();
			String newString = Permission.getItemName(oldString);
			
			model.setPermissions(newString);
		}
		return rolesList;
	}
	
}
